package 贪心算法;

public class 种花问题 {

    public static boolean canPlaceFlowers(int[] flowerbed, int n) {
        int start = -2;
        int length = flowerbed.length;
        int num = 0;
        for (int i = 0; i < length; i++) {
            if (flowerbed[i] == 1){
                num += (i-start)/2 -1;
                if (num >= n){
                    return true;
                }
                start = i;
            }
        }
        if (start != length-1){
            num += (length - start -1)/2 ;
        }

        return num>= n;
    }

    public static void main(String[] args) {
        int[] fl = {0,0,0,1,0,0,0,1,0};
        System.out.println(canPlaceFlowers(fl,3));
    }
}
